package org.vm.cmbcdirect.utils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Created by mv on 2016/3/22.
 */
public final class BaseUtil {
    private static String appID;
    private static String appSecret;
    private static String url;
    private static String token;
    private static String encodingAESKey;
    private static String faceApiKey;
    private static String faceApiSecret;
    private static String faceApiUrl;
    private static File uploadBaseFile;
    private static File faceUploadFile;
    private static File faceTmpFile;

    static {
        // 解析配置文件
        Properties properties = new Properties();
        try {
            InputStream in = BaseUtil.class.getResourceAsStream("/wechat.properties");
            //将属性文件流装载到Properties对象中
            properties.load(in);
            appID = properties.getProperty("AppID").trim();
            appSecret = properties.getProperty("AppSecret").trim();
            url = properties.getProperty("URL").trim();
            token = properties.getProperty("Token").trim();
            encodingAESKey = properties.getProperty("EncodingAESKey").trim();
            faceApiKey = properties.getProperty("FACE.APIKey").trim();
            faceApiSecret = properties.getProperty("FACE.APISecret").trim();
            faceApiUrl = properties.getProperty("FACE.APIUrl").trim();
        } catch (IOException e) {
            e.printStackTrace();
        }


        // 创建文件夹
        uploadBaseFile = new File(BaseUtil.class.getResource("/").getPath().replace("WEB-INF/classes/", "upload/"));
        if (!uploadBaseFile.exists()) {
            uploadBaseFile.mkdirs();
        }

        // 创建文件夹
        faceUploadFile = new File(BaseUtil.class.getResource("/").getPath().replace("WEB-INF/classes/", "upload/faceImg/"));
        if (!faceUploadFile.exists()) {
            faceUploadFile.mkdirs();
        }

        // 创建临时目录
        faceTmpFile = new File(BaseUtil.class.getResource("/").getPath().replace("WEB-INF/classes/", "upload/faceTmp/"));
        if (!faceTmpFile.exists()) {
            faceTmpFile.mkdirs();
        }
    }

    public static String getAppID() {
        return appID;
    }

    public static void setAppID(String appID) {
        BaseUtil.appID = appID;
    }

    public static String getAppSecret() {
        return appSecret;
    }

    public static void setAppSecret(String appSecret) {
        BaseUtil.appSecret = appSecret;
    }

    public static String getUrl() {
        return url;
    }

    public static void setUrl(String url) {
        BaseUtil.url = url;
    }

    public static String getToken() {
        return token;
    }

    public static void setToken(String token) {
        BaseUtil.token = token;
    }

    public static String getEncodingAESKey() {
        return encodingAESKey;
    }

    public static void setEncodingAESKey(String encodingAESKey) {
        BaseUtil.encodingAESKey = encodingAESKey;
    }

    public static String getFaceApiKey() {
        return faceApiKey;
    }

    public static void setFaceApiKey(String faceApiKey) {
        BaseUtil.faceApiKey = faceApiKey;
    }

    public static String getFaceApiSecret() {
        return faceApiSecret;
    }

    public static void setFaceApiSecret(String faceApiSecret) {
        BaseUtil.faceApiSecret = faceApiSecret;
    }

    public static String getFaceApiUrl() {
        return faceApiUrl;
    }
    public static void setFaceApiUrl(String faceApiUrl) {
        BaseUtil.faceApiUrl = faceApiUrl;
    }

    public static File getUploadBaseFile() {
        return uploadBaseFile;
    }

    public static File getFaceUploadFile() {
        return faceUploadFile;
    }

    public static File getFaceTmpFile() {
        return faceTmpFile;
    }
}
